/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function initialCap(field) {
    field.value = field.value.substr(0, 1).toUpperCase() + field.value.substr(1);
}

function upperCase(x)
{
    var y=document.getElementById(x).value;
    document.getElementById(x).value=y.toUpperCase();
}

function IsNumeric(value) {
    var log=value.length;
    var sw="S";
    for (x=0; x<log; x++) {
        v1=value.substr(x,1);
        v2 = parseInt(v1);
        if (isNaN(v2)) {
            sw= "N";
        }//check if numeric value
    }
    if (sw=="S") {
        return true;
    }
    else {
        return false;
    }
}

var slap1=false;
var slap2=false;
function formatDate(date) {
    var lon = date.length;
    var day;
    var month;
    var year;
    if ((lon>=2) && (slap1==false)) {
        day=date.substr(0,2);
        if ((IsNumeric(day)==true) && (day<=31) && (day!="00")) {
            date=date.substr(0,2)+"/"+date.substr(3,7);
            slap1=true;
        }
        else {
            date="";
            slap1=false;
        }
    }
    else{
        day=date.substr(0,1);
        if (IsNumeric(day)==false)     {
            date="";
        }
        if ((lon<=2) && (slap1=true)) {
            date=date.substr(0,1);
            slap1=false;
        }
    }
    if ((lon>=5) && (slap2==false)) {
        month=date.substr(3,2);
        if ((IsNumeric(month)==true) &&(month<=12) && (month!="00")) {
            date=date.substr(0,5)+"/"+date.substr(6,4);
            slap2=true;
        }
        else {
            date=date.substr(0,3);
            slap2=false;
        }
    }
    else {
        if ((lon<=5) && (slap2=true)) {
            date=date.substr(0,4);
            slap2=false;
        }
    }
    if (lon>=7) {
        year=date.substr(6,4);
        if (IsNumeric(year)==false) {
            date=date.substr(0,6);
        }
        else {
            if (lon==10){
                if ((year==0) || (year<1500) || (year>2100)) {
                    date=date.substr(0,6);
                }
            }
        }
    }
    if (lon>=10) {
        date=date.substr(0,10);
        day=date.substr(0,2);
        month=date.substr(3,2);
        year=date.substr(6,4);
        // Año no viciesto y es febrero y el day es mayor a 28
        if ( (year%4!= 0) && (month ==02) && (day>28) ) {
            date=date.substr(0,2)+"/";
        }
        else{
            if((month ==02)&& (day>29)){
                date=date.substr(0,2)+"/";
            }
        }
        if ((month==04)||(month==06)||(month==09)||(month==11)){
            if (day>30){
                date=date.substr(0,2)+"/";
            }
        }
    }
    return (date);

}

var nav = window.Event ? true : false;
function acceptNum(evt) {
    // NOTA: Backspace = 8->si, Enter = 13->no, '0' = 48, '9' = 57, '.'=46->si
    var key = nav ? evt.which : evt.keyCode;
    return (key < 13 || (key >= 48 && key <= 58));
}
// key ==46 ||

var nav1 = window.Event ? true : false;
function acceptNumDecimal(evt) {
    // NOTA: Backspace = 8->si, Enter = 13->no, '0' = 48, '9' = 57, '.'=46->si
    var key = nav1 ? evt.which : evt.keyCode;
    return (key < 13 || key == 46 || (key >= 48 && key <= 58));
}

function Validate()
{
    var chkdate = document.getElementById("date[]").value
    if(document.getElementById("date[]").value == "")
    {
        alert("Please enter the Date..!!")
        if(chkdate.match(/^[0-9]{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])/))
        {
            alert('works out');
        }
        else
        {
            alert("date format is wrong")
        }
        return false
    }
    else if(document.getElementById("from[]").value == "")
    {
        alert("Please enter the from value..!!")
        return false
    }
    else{
        return true
    }
}



function fixFloat(fld,sep)
{ // decimal number check/complainer
    if(!fld.value.length||fld.disabled) return true; // blank fields are the domain of requireValue
    var val= fld.value;
    if(typeof(sep)!='undefined') val= val.replace(new RegExp(sep,'g'),'');
    val= parseFloat(fld.value);
    if(isNaN(val))
    { // parse error
        status= 'The '+fieldname(fld)+' field must contain a number.';
        return false;
    }
    fld.value= val;
    return true;
}

